import request from '@/utils/request'

export function add(data) {
  return request({
    url: 'api/circulation/add',
    method: 'post',
    data
  })
}

export function addDrug(data) {
  return request({
    url: 'api/circulation/add',
    method: 'post',
    data
  })
}
export function drugDetail() {
  return request({
    url: 'api/circulation/detail',
    method: 'get'
  })
}

export function getDrugs(data) {
  let url = 'api/circulation/getDrugs'
  const param = _getParams(data)
  if (param) url = url + '?' + param
  return request({
    url: url,
    method: 'get'
  })
}
export function getSuppliers() {
  return request({
    url: 'api/circulation/getDrugCirculation',
    method: 'get'
  })
}

export function updateDrug(data) {
  return request({
    url: 'api/circulation/update',
    method: 'post',
    data
  })
}

export function edit(data) {
  return request({
    url: 'api/schedule',
    method: 'put',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/schedule/',
    method: 'delete',
    data: ids
  })
}

export function queryStoreName() {
  return request({
    url: 'auth/queryStoreName',
    method: 'get'
  })
}
export function queryStore(account) {
  return request({
    url: 'store/cpt/getCptStore?storeId=' + account,
    method: 'get'
  })
}

const _getParams = function(data) {
  if (!data) return null
  let res = ''
  for (const key in data) {
    res += '&' + key + '=' + data[key]
  }
  return res.substring(1)
}

export default { add, edit, del }
